"""
单例模式
"""
class Singleton(object):
    # 私有属性，表示当前实例
    __instance = None
    # 私有属性，保证只实例化一次
    __init_flag = False

    # 创建对象
    def __new__(cls, *args, **kwargs):
        if cls.__instance is None:
            cls.__instance = object.__new__(cls)

        # 返回引用
        return cls.__instance

    # 初始化对象
    def __init__(self, name):
        # 保证只初始化一次
        if not self.__init_flag:
            print("init")
            self.name = name
            self.__init_flag = True

s1 = Singleton("s1")
s2 = Singleton("s2")
print(s1.name + s2.name)
print(s1 == s2)
